package hot_problems_100;

public class P20_0240 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n=matrix[0].length;
        int x = 0, y = n-1;

        while(x<m && y>=0){
            if(matrix[x][y] == target) return true;
            else if(matrix[x][y] > target){
                y--;
            } else {
                x++;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[][] matrix = new int[][] {
                {1, 2, 3, 4, 5},
                {6, 7, 8, 9, 10},
                {11, 12, 13, 14, 15},
                {16, 17, 18, 19, 20},
                {21, 22, 23, 24, 25}
        };
        ;
        int target = 3;
        System.out.println(new P20_0240().searchMatrix(matrix, target));
    }
}
